/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 商店
	/// module : structs
	/// </summary>
	public class ShopPOD : IPOD 
    {
        public readonly static Func<ShopPOD> FACTORY = () => new ShopPOD();
		public static Func<ShopPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 配置id
        /// </summary>
		public int cid;
		/// <summary>
        /// 可售商品列表
        /// </summary>
        private List<int> m_goodsList;
		/// <summary>
        /// 下次刷新时间点
        /// </summary>
		public int nextRefreshTime;
		/// <summary>
        /// 免费刷新次数
        /// </summary>
		public int freeRefreshCnt;
		/// <summary>
        /// 道具刷新次数
        /// </summary>
		public int itemRefreshCnt;
		/// <summary>
        /// 付费刷新次数
        /// </summary>
		public int payRefreshCnt;
		/// <summary>
        /// 已购买的商店index，从1开始
        /// </summary>
        private List<int> m_buyGoodsList;
		
		
        public List<int> goodsList
        {
            get
            {
                if(m_goodsList == null)
                {
                    m_goodsList = new();
                }
                return m_goodsList;
            }
            private set => m_goodsList = value;
        }
        public List<int> unsafe_goodsList
        {
        	get => m_goodsList;
        	set => m_goodsList = value;
        }
        public List<int> buyGoodsList
        {
            get
            {
                if(m_buyGoodsList == null)
                {
                    m_buyGoodsList = new();
                }
                return m_buyGoodsList;
            }
            private set => m_buyGoodsList = value;
        }
        public List<int> unsafe_buyGoodsList
        {
        	get => m_buyGoodsList;
        	set => m_buyGoodsList = value;
        }
		
		/*-- constructors --*/
		public ShopPOD() {}
		public ShopPOD(int cid, List<int> goodsList, int nextRefreshTime, int freeRefreshCnt, int itemRefreshCnt, int payRefreshCnt, List<int> buyGoodsList) {
			this.cid = cid;
			this.m_goodsList = goodsList;
			this.nextRefreshTime = nextRefreshTime;
			this.freeRefreshCnt = freeRefreshCnt;
			this.itemRefreshCnt = itemRefreshCnt;
			this.payRefreshCnt = payRefreshCnt;
			this.m_buyGoodsList = buyGoodsList;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_int(cid);
            _out.Write_list_int(m_goodsList); 
            _out.Write_int(nextRefreshTime);
            _out.Write_int(freeRefreshCnt);
            _out.Write_int(itemRefreshCnt);
            _out.Write_int(payRefreshCnt);
            _out.Write_list_int(m_buyGoodsList); 
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            cid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            m_goodsList = _in.Read_list_int();
            if(!_in.HasRemaining()) return;
            nextRefreshTime = _in.Read_int();
            if(!_in.HasRemaining()) return;
            freeRefreshCnt = _in.Read_int();
            if(!_in.HasRemaining()) return;
            itemRefreshCnt = _in.Read_int();
            if(!_in.HasRemaining()) return;
            payRefreshCnt = _in.Read_int();
            if(!_in.HasRemaining()) return;
            m_buyGoodsList = _in.Read_list_int();
        }
		
		public ShopPOD Clone() {
            ShopPOD o = DynamicFactory();
            o.cid = cid;
            if (m_goodsList != null) {
                o.m_goodsList = new (m_goodsList);
            }
            o.nextRefreshTime = nextRefreshTime;
            o.freeRefreshCnt = freeRefreshCnt;
            o.itemRefreshCnt = itemRefreshCnt;
            o.payRefreshCnt = payRefreshCnt;
            if (m_buyGoodsList != null) {
                o.m_buyGoodsList = new (m_buyGoodsList);
            }
            return o;
        }
        
        public void Clear() {
            cid = default;
            m_goodsList = default;
            nextRefreshTime = default;
            freeRefreshCnt = default;
            itemRefreshCnt = default;
            payRefreshCnt = default;
            m_buyGoodsList = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "ShopPOD [";
			str += "cid=";
			str += cid;
			str += ", goodsList=";
			str += m_goodsList.ToString<int>();
			str += ", nextRefreshTime=";
			str += nextRefreshTime;
			str += ", freeRefreshCnt=";
			str += freeRefreshCnt;
			str += ", itemRefreshCnt=";
			str += itemRefreshCnt;
			str += ", payRefreshCnt=";
			str += payRefreshCnt;
			str += ", buyGoodsList=";
			str += m_buyGoodsList.ToString<int>();
			str += "]";
			return str;
		}
		
	}
}